package com.wofish.web.controller.goods;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wofish.common.annotation.Log;
import com.wofish.common.enums.BusinessType;
import com.wofish.goods.domain.GoodsTypeProps;
import com.wofish.goods.service.IGoodsTypePropsService;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.utils.poi.ExcelUtil;

/**
 * 商品类型属性 信息操作处理
 * 
 * @author wofish
 * @date 2019-04-14
 */
@Controller
@RequestMapping("/goods/goodsTypeProps")
public class GoodsTypePropsController extends BaseController
{
    private String prefix = "goods/goodsTypeProps";
	
	@Autowired
	private IGoodsTypePropsService goodsTypePropsService;
	
	@RequiresPermissions("goods:goodsTypeProps:view")
	@GetMapping()
	public String goodsTypeProps()
	{
	    return prefix + "/goodsTypeProps";
	}
	
	/**
	 * 查询商品类型属性列表
	 */
	@RequiresPermissions("goods:goodsTypeProps:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(GoodsTypeProps goodsTypeProps)
	{
		startPage();
        List<GoodsTypeProps> list = goodsTypePropsService.selectGoodsTypePropsList(goodsTypeProps);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出商品类型属性列表
	 */
	@RequiresPermissions("goods:goodsTypeProps:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GoodsTypeProps goodsTypeProps)
    {
    	List<GoodsTypeProps> list = goodsTypePropsService.selectGoodsTypePropsList(goodsTypeProps);
        ExcelUtil<GoodsTypeProps> util = new ExcelUtil<GoodsTypeProps>(GoodsTypeProps.class);
        return util.exportExcel(list, "goodsTypeProps");
    }
	
	/**
	 * 新增商品类型属性
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品类型属性
	 */
	@RequiresPermissions("goods:goodsTypeProps:add")
	@Log(title = "商品类型属性", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(GoodsTypeProps goodsTypeProps)
	{		
		return toAjax(goodsTypePropsService.insertGoodsTypeProps(goodsTypeProps));
	}

	/**
	 * 修改商品类型属性
	 */
	@GetMapping("/edit/{propsId}")
	public String edit(@PathVariable("propsId") Long propsId, ModelMap mmap)
	{
		GoodsTypeProps goodsTypeProps = goodsTypePropsService.selectGoodsTypePropsById(propsId);
		mmap.put("goodsTypeProps", goodsTypeProps);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品类型属性
	 */
	@RequiresPermissions("goods:goodsTypeProps:edit")
	@Log(title = "商品类型属性", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(GoodsTypeProps goodsTypeProps)
	{		
		return toAjax(goodsTypePropsService.updateGoodsTypeProps(goodsTypeProps));
	}
	
	/**
	 * 删除商品类型属性
	 */
	@RequiresPermissions("goods:goodsTypeProps:remove")
	@Log(title = "商品类型属性", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(goodsTypePropsService.deleteGoodsTypePropsByIds(ids));
	}
	
}
